﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using NewDDSys.IDAL;
using NewDDSys.Entity;
using NewDDSys.Utility;
using System.Text;

namespace NewDDSys.ORADAL
{
    public class WeekotherDAL:IWeekotherDAL
    {
        public int AddWeekother(WeekotherInfo wo)
        {
            OracleParameter[] prams = {
                DALHelper.MakeInParam(":num", OracleType.VarChar, wo.Num),
                
                DALHelper.MakeInParam(":sday", OracleType.VarChar, wo.Sday),
                DALHelper.MakeInParam(":eday", OracleType.VarChar, wo.Eday),
                DALHelper.MakeInParam(":info", OracleType.VarChar, wo.Info),
                DALHelper.MakeInParam(":xday", OracleType.VarChar, wo.Xday)
                

            };
            return (DALHelper.RunCommand(@"insert into dd.weekother (num, sday, eday, info, xday) values (:num, to_date(:sday,'yyyy-mm-dd'), to_date(:eday,'yyyy-mm-dd'), :info, to_date(:xday,'yyyy-mm-dd'))", prams));
        }
        public int UpdateWeekother(string num, string sday, string eday, string info, string jx)
        {
            OracleParameter[] prams = {
                DALHelper.MakeInParam(":num", OracleType.VarChar, num),
                
                DALHelper.MakeInParam(":sday", OracleType.VarChar, sday),
                DALHelper.MakeInParam(":eday", OracleType.VarChar, eday),
                DALHelper.MakeInParam(":info", OracleType.VarChar, info),
                
                DALHelper.MakeInParam(":jx", OracleType.VarChar, jx)

            };
            return (DALHelper.RunCommand(@"update dd.weekother set sday = to_date(:sday,'yyyy-mm-dd'), eday = to_date(:eday,'yyyy-mm-dd'), info = :info, jx = :jx where num = :num", prams));
        }
        public int UpdateWeekotherJX(string num, string jx)
        {
            OracleParameter[] prams = {
                DALHelper.MakeInParam(":num", OracleType.VarChar, num),
                
                DALHelper.MakeInParam(":jx", OracleType.VarChar, jx)

            };
            return (DALHelper.RunCommand(@"update dd.weekother set jx = :jx where num = :num", prams));
        }
        public int Del(string num)
        {
            OracleParameter[] prams = {
                
                DALHelper.MakeInParam(":num", OracleType.VarChar, num)                      
            };
            return (DALHelper.RunCommand(@"delete from dd.weekother where NUM = :num", prams));
        }
        public DataSet Select(string num)
        {
            OracleParameter[] prams = {
                DALHelper.MakeInParam(":num", OracleType.VarChar, num)
            };
            return (DALHelper.RunProcReturn(@"select * from dd.weekother where NUM = :num", prams, "Sbynum"));
        }
        public DataSet SelectByDay(string sday)
        {
            OracleParameter[] prams = {
                DALHelper.MakeInParam(":sday", OracleType.VarChar, sday)
            };
            return (DALHelper.RunProcReturn(@"select * from dd.weekother where xday = to_date(:sday,'yyyy-mm-dd')", prams, "Sbyday"));
        }
        public string AUTOID()
        {

            string num = "";
            object time = DALHelper.ExecuteSQLScalar(@"select sysdate from dual");
            num = "wo" + time.ToString();


            return num;
        }
    }
}
